#include <iostream>
using namespace std;

class Singleton{
public:
    static Singleton * getInstance(){
        if( instance==NULL )
            instance = new Singleton();
        return instance;
    }
    
    ~Singleton(){;}
    void setVal( const int & v ){ st = v; }
    const int & getVal()const{ return st; }
    const int & getNum()const{ return num; }
    
private:
    static int num;
    static Singleton *instance;
    int st;
    Singleton():st(0){ num++;}   
};

//static Singleton *single = Singleton::getInstance();
int Singleton::num = 0;
Singleton *Singleton::instance = NULL;

int main()
{
    Singleton *single1 = Singleton::getInstance();
    single1->setVal( 10 );
    cout << single1->getVal() <<",instance number: " << single1->getNum() << endl;

    Singleton *single2 = Singleton::getInstance();
    single2->setVal( 20 );
    cout << single2->getVal() <<",instance number: " << single2->getNum() << endl;

    cout << single1->getVal() <<",instance number: " << single1->getNum() << endl;    
}